package com.youyicloud.api;

import com.youyicloud.constants.Constants;
import com.youyicloud.service.EquipmentPayService;
import com.youyicloud.service.EquipmentService;
import com.youyicloud.vo.ResponseBodyEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("equipmentPay")
public class EquipmentPayApi {
    @Autowired
    private EquipmentPayService equipmentPayService;

    @Autowired
    private EquipmentService equipmentService;


    @RequestMapping("saveEquipmentPay")
    public ResponseBodyEntity saveEquipmentPay(String imeiMac,String equipmentBrevityCode,String payUrl,Integer equipmentTypeId){
        List<HashMap> resultMaps = equipmentService.findByImeiMac(imeiMac);
        ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
        if(resultMaps!=null && resultMaps.size()>0){
            responseBodyEntity.setMsg("绑定失败,imei码已存在");
            responseBodyEntity.setState(Constants.FAILURE);
            return responseBodyEntity;
        }
        if(payUrl.indexOf("/")>10){
            responseBodyEntity.setMsg("绑定失败,支付链接不正确");
            responseBodyEntity.setState(Constants.FAILURE);
            return responseBodyEntity;
        }
        responseBodyEntity.setData(equipmentPayService.saveEquipmentPay(imeiMac,equipmentBrevityCode,payUrl,equipmentTypeId));
        responseBodyEntity.setMsg("绑定成功");
        responseBodyEntity.setState(Constants.SUCCEED);
        return responseBodyEntity;
    }

    @RequestMapping("deleteByEquipmentPayId")
    public ResponseBodyEntity deleteByEquipmentPayId(Integer equipmentPayId){
        ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
        equipmentPayService.deleteByEquipmentPayId(equipmentPayId);
        responseBodyEntity.setMsg("解绑成功");
        responseBodyEntity.setState(Constants.SUCCEED);
        return responseBodyEntity;
    }
    
}
